package com.guan.ordering_sys.generator.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guan.ordering_sys.common.StateCode;
import com.guan.ordering_sys.exception.BaseException;
import com.guan.ordering_sys.generator.entity.Company;
import com.guan.ordering_sys.generator.mapper.CompanyMapper;
import com.guan.ordering_sys.generator.service.CompanyService;
import com.guan.ordering_sys.vo.CompanyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  CompanyServiceImpl 服务实现类
 * </p>
 *
 * @author 关远键
 * @since 2021-06-18
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {

    @Autowired
    private CompanyMapper companyMapper;

    /**
     * 根据公司编号获取公司信息
     * @author 关远键
     * @date 2021/6/27 11:08
     * @param id
     * @return com.guan.ordering_sys.vo.CompanyVo
     */
    @Override
    public CompanyVo getById(Long id) {
        Company company = companyMapper.getById(id);

        if (company == null) {
            throw new BaseException(StateCode.NOT_FOUND);
        }

        //设置参数
        CompanyVo companyVo = new CompanyVo();
        companyVo.setId(company.getCompanyId());
        companyVo.setParent(company.getCompanyParent());
        companyVo.setName(company.getCompanyName());
        companyVo.setType(company.getCompanyType());

        return companyVo;
    }

}
